package com.skyline.common.util;

import java.util.Locale;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MessageUtils {
	private static final Log LOGGER = LogFactory.getLog(MessageUtils.class);

	public static String getMessage(String key) {
		return getMessage(key, null, null, null);
	}

	public static String getMessage(String key, String defaultMsg) {
		return getMessage(key, null, defaultMsg, null);
	}

	public static String getMessage(String key, String[] args) {
		return getMessage(key, args, null, null);
	}

	public static String getMessage(String key, String[] args, String defaultMsg) {
		return getMessage(key, args, defaultMsg, null);
	}

	private static String getMessage(String key, String[] args, String defaultMsg, Locale locale) {
		if (locale == null) {
			locale = Locale.getDefault();
		}
		String message = null;
		try {
			message = SpringUtils.getApplicationContext().getMessage(key, args, defaultMsg, locale);
		} catch (Exception e) {
			LOGGER.info("读取[" + key + "]发生错误：", e);
			message = "";
		}
		return message;
	}
}
